#编辑页自动化测试用例
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

from BlogSystemAutoTest.Common.Utils import BlogDriver
from BlogSystemAutoTest.testTask.BlogLogin import Alert


class Editor:
    driver=""
    url=""
    def __init__(self):
        self.driver=BlogDriver.driver
        self.url="http://47.99.68.28:8888/blog/blog_html/blog_editor.html"

    #登陆状态下的编辑
    def EditorNormal(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(5)").click()
        self.driver.find_element(By.ID,"blog_title").clear()
        self.driver.find_element(By.ID,"inPutTex").clear()

        self.driver.find_element(By.ID,"blog_title").send_keys("自动化测试用例")
        self.driver.find_element(By.ID,"inPutTex").send_keys("自动化测试用例123")
        self.driver.find_element(By.ID,"blog_create").click()
        Alert(self.driver)
        title=self.driver.find_element(By.CSS_SELECTOR,"#bloglist > div:nth-child(1) > h2").text
        try:
            assert title=="自动化测试用例"
        except AssertionError as e:
            BlogDriver.getScreenShort()
        self.driver.find_element(By.ID,"out").click()
        Alert(self.driver)
    def EditorABNormal(self):
        self.driver.get(self.url)
        self.driver.find_element(By.ID, "blog_title").send_keys("自动化测试用例")
        self.driver.find_element(By.ID, "inPutTex").send_keys("自动化测试用例123")
        self.driver.find_element(By.ID, "blog_create").click()

        Alert(self.driver)
        try:
            self.driver.find_element(By.ID, "blog_title")
        except NoSuchElementException:
            BlogDriver.getScreenShort()
        self.driver.find_element(By.ID, "out").click()
        Alert(self.driver)